package org.springcloud.plugin.framework.strategy.configuration;

import org.springcloud.plugin.framework.strategy.constant.StrategyConstant;
import org.springcloud.plugin.framework.strategy.isolation.IsolationRegisterStrategy;
import org.springcloud.plugin.framework.strategy.matcher.DiscoveryAntPathMatcherStrategy;
import org.springcloud.plugin.framework.strategy.matcher.DiscoveryMatcherStrategy;
import org.springcloud.plugin.framework.strategy.wrapper.StrategyWrapper;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.netflix.ribbon.RibbonClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author yanggld
 * @Date 2020/1/21-21:04
 * @Description
 */
@Configuration
@RibbonClients(defaultConfiguration = { StrategyLoadBalanceConfiguration.class })
public class StrategyAutoConfiguration {

	@Bean
	@ConditionalOnMissingBean
	public DiscoveryMatcherStrategy discoveryMatcherStrategy() {
		return new DiscoveryAntPathMatcherStrategy();
	}

	@Bean
	@ConditionalOnMissingBean
	@ConditionalOnProperty(value = StrategyConstant.SPRING_APPLICATION_STRATEGY_REGISTER_ISOLATION_ENABLED, matchIfMissing = false)
	public IsolationRegisterStrategy isolationRegisterStrategy() {
		return new IsolationRegisterStrategy();
	}


	@Bean
	public StrategyWrapper strategyWrapper() {
		return new StrategyWrapper();
	}
}
